using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Microsoft.DirectX;
using NovodexWrapper;
using OpenPanekitEditor;
using OpenPanekitEditor.Panel;

namespace OriginalPanels
{
    [PanelAttribute("Original::Jet", IsDeadEnd = true, HasPivot = true, LocalD3DModelName = "Model\\Jet_P.X", PivotD3DModelName = "Model\\Jet_S.X")]
    public class Jet:PanelBase,IPanel
    {
        public Image IconImage { get{return Properties.Resources.ElementIcon_Jet;} }
        public Jet()
        {
            ParameterDictionary[typeof(JetParameter_Thrust)] = new JetParameter_Thrust();
        }
        Matrix l_to_r_matrix = Matrix.Identity;
        public Matrix LocalToRootMatrix
        {
            get { return l_to_r_matrix; }
            set { l_to_r_matrix = value; }
        }
        Matrix p_to_r_matrix = Matrix.Identity;
        public Matrix PivotToRootMatrix
        {
            get { return p_to_r_matrix; }
            set { p_to_r_matrix = value; }
        }

        public Matrix PivotMatrix
        {
            get { return Matrix.Identity; }
            set { }
        }

        protected NxRevoluteJoint nx_joint;
        NxSpringDesc nx_jointspring = null;
        protected Vector3 local_axis;
        public override NxActor InitNx(NxScene scene,NxActor parent,Matrix pmatrix)
        {
            local_axis = new Vector3(0, 1, 0);
            Matrix globalpose = pmatrix * parent.getGlobalOrientation();
            current_actor = NovodexUtil.createBoxActor(scene, Vector3.Empty, globalpose, PanelUtil.PanelDensity);
            current_actor.setGlobalOrientation(globalpose);
            Vector3 world_anchor = Vector3.TransformCoordinate(Vector3.Empty, globalpose);
            Vector3 world_axis = Vector3.TransformNormal(local_axis, globalpose);
            nx_joint = NovodexUtil.createRevoluteJoint(scene, parent, current_actor, world_anchor, world_axis,false);

            //CreateJointShape(parent,current_actor, pmatrix);
            return current_actor;
        }
        Vector3 th_force = new Vector3(0, 0, 0);
        public override void UpdateNxParameter(float dt)
        {
            th_force.Y = ParameterDictionary[typeof(JetParameter_Thrust)].Value;
            current_actor.AngularVelocity = new Vector3(0, th_force.Y, 0);
            //current_actor.addTorque(new Vector3(0, ParameterDictionary[typeof(JetParameter_Thrust)].Value, 0), NxForceMode.NX_FORCE);
            current_actor.addLocalForce(th_force, NxForceMode.NX_ACCELERATION);
        }
    }
    public class JetParameter_Thrust : OpenPanekitEditor.Panel.Parameter
    {
        public override float UpperLimit
        {
            get { return 100f; }
        }
        public override float LowerLomit
        {
            get { return -100f; }
        }
        public override float Quantize
        {
            get { return 5f; }
        }
        public override String Title
        {
            get { return Resouces.Strings.SettingParameter_JetThrust; }
        }
        public override String Unit
        {
            get { return "N"; }
        }
        public override bool CanAssignControl
        {
            get { return true; }
        }
    }
}